package Beans;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author PhongLK60473
 */
public class Login extends User {
    private boolean Loged=false;

    public boolean isLoged() {
        return Loged;
    }

    public void setLoged(boolean Loged) {
        this.Loged = Loged;
    }
    
    public Login(String Username, String Password) {
        super(Username, Password);
        Database db = new Database();
        if ( db.isOK ){
            String strSQL = "SELECT * FROM TBL_Account WHERE Username = ?"
                    + " AND Password = ?";
            try{
                PreparedStatement stm = db.con.prepareCall(strSQL);
                stm.setString(1, this.getUsername());
                stm.setString(2, this.getPassword());

                ResultSet rs = stm.executeQuery();
                if(rs.next()){
                    this.Loged = true;
                    this.setLastname(rs.getString("LastName"));
                    this.setAdmin(rs.getBoolean("isAdmin"));
                }else{
                    this.Loged = false;
                }
            } catch (SQLException e){
                System.out.println(e.getMessage());
            }
        }
    }
}
